﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using CWB.Common.Exceptions;
using CWB.Common.Constant;
using CWB.Web.MVC.ActionResults;
using CWB.Web.MVC.BaseController;
using CWB.Web.MVC.ReturnResult;

namespace CWB.Web.MVC.Filters
{
    public class PermissionFilterAttvibute : ActionFilterAttribute
    {
        public LoginType loginType { get; set; }

        protected SessionData sessionData = new SessionData();
        
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            SessionData sessionData = new SessionData();
            if (sessionData.trading == null)
            {
                RejectRequestResult.RejectRequest(filterContext, RejectReason.PermissionDeny, sessionData);
            }
            else
            {
                if ((int)sessionData.trading.loginType > (int)loginType)
                {
                    RejectRequestResult.RejectRequest(filterContext, RejectReason.PermissionDeny, sessionData);
                }
                else
                {
                    base.OnActionExecuting(filterContext);
                }
            }
        }
    }
}
